package jmine.tec.services.export.export;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jmine.tec.services.api.ActionsEnum;
import jmine.tec.services.api.export.AbstractEntityExporter;
import jmine.tec.services.api.export.DefaultExportAction;
import jmine.tec.services.api.export.ReferenceMap;
import jmine.tec.services.export.impl.ExportUtils;
import jmine.tec.services.io.ServiceBean;
import bancosys.tec.services.export.domain.AssociatedMockEntity;
import bancosys.tec.services.export.domain.MockEntity;

public class OtherMockEntityExporter extends AbstractEntityExporter<MockEntity> {

    public OtherMockEntityExporter() {
        super(DefaultExportAction.INCLUIR);
    }

    public List<ServiceBean> export(ReferenceMap referenceMap, MockEntity entity) {
        ServiceBean bean = new ServiceBean();
        bean.setName("MockEntity");
        bean.setAction(ActionsEnum.INCLUIR);
        bean.getParameters().put("Value", entity.getValue());
        bean.getParameters().put("ID", referenceMap.addReference(entity, "mock"));
        return Collections.singletonList(bean);
    }

    @Override
    public List<Object> exportAfter(MockEntity entity) {
        List<Object> associations = new ArrayList<Object>();
        for (AssociatedMockEntity associated : entity.getReferences()) {
            associations.add(ExportUtils.wrap(DefaultExportAction.INCLUIR, new MockEntityAssociation(entity, associated)));
        }
        return associations;
    }
}